package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;

public class REPEAT extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    Object localObject1 = paramArrayOfObject[0];
    int i = 1;
    if (paramArrayOfObject.length > 1)
    {
      localObject2 = paramArrayOfObject[1];
      if (localObject2 instanceof Number)
        i = Math.abs(((Number)localObject2).intValue());
    }
    Object localObject2 = new StringBuffer();
    for (int j = 0; j < i; ++j)
      ((StringBuffer)localObject2).append(localObject1);
    return ((StringBuffer)localObject2).toString();
  }

  public Function.Type getType()
  {
    return Function.TEXT;
  }

  public String getCN()
  {
    return "REPEAT(text,number_times): 根据指定的次数重复显示文本。REPEAT函数可用来显示同一字符串，并对单元格进行填充。\nText:需要重复显示的文本或包含文本的单元格引用。\nNumber_times:指定文本重复的次数，且为正数。如果number_times为0，REPEAT函数将返回“”（空文本）。如果number_times不是整数，将被取整。REPEAT函数的最终结果通常不大于32767个字符。\n备注:\n    该函数可被用于在工作表中创建简单的直方图。\n示例:\nREPEAT(\"$\",4)等于“$$$$”。\n如果单元格B10的内容为“你好”，REPEAT(B10,3)等于“你好你好你好”。";
  }

  public String getEN()
  {
    return "REPEAT(text,number_times): Repeats text a given number of times. Use REPEAT to fill a cell with a number of instances of a text string.\nText is the text you want to repeat.\nNumber_times is a positive number specifying the number of times to repeat text.\n\nRemarks:\n1. If number_times is 0 (zero), REPEAT returns \"\" (empty text).\n2. The result of the REPEAT function cannot be longer than 32,767 characters, or REPEAT returns #VALUE!.\n3. It could be used to produce histogram.\n\nExample:\n   REPEAT(\"$\",4) = \"$$$$\"";
  }
}